"""
账单产品接口模型
"""

from jlpay.model.base import OrgBaseReq, BaseResponse


class AccountFileDownloadRequest(OrgBaseReq):
  """对账下载请求"""

  API_URL = "/open/bill/download/query"

  def __init__(self):
    """初始化对账下载请求"""
    super().__init__()
    self.bill_type = None
    self.dt = None

  def set_bill_type(self, bill_type):
    """
    设置账单类型

    Args:
        bill_type: 账单类型 (1：日交易账单，20：管控资金账单，21：管控冻结账单)

    Returns:
        AccountFileDownloadRequest实例
    """
    self.bill_type = bill_type
    return self

  def set_dt(self, dt):
    """
    设置查询日期

    Args:
        dt: 查询日期，格式为yyyyMMdd

    Returns:
        AccountFileDownloadRequest实例
    """
    self.dt = dt
    return self

  def to_dict(self):
    """
    转换为字典

    Returns:
        请求参数字典
    """
    return {
      "bill_type": self.bill_type,
      "dt": self.dt
    }


class AccountFileDownloadResponse(BaseResponse):
  """对账下载响应"""

  def __init__(self, response_dict=None):
    """
    初始化对账下载响应

    Args:
        response_dict: 响应字典
    """
    super().__init__(response_dict)
    self.file_url = None

    if response_dict:
      self.file_url = response_dict.get('file_url')


class TransChargeQueryRequest(OrgBaseReq):
  """手续费查询请求"""

  API_URL = "/open/bill/trans-charge/query"

  def __init__(self):
    """初始化手续费查询请求"""
    super().__init__()
    self.order_id = None

  def set_order_id(self, order_id):
    """
    设置嘉联订单号

    Args:
        order_id: 嘉联订单号

    Returns:
        TransChargeQueryRequest实例
    """
    self.order_id = order_id
    return self


class TransChargeQueryResponse(BaseResponse):
  """手续费查询响应"""

  def __init__(self, response_dict=None):
    """
    初始化手续费查询响应

    Args:
        response_dict: 响应字典
    """
    super().__init__(response_dict)
    self.merch_no = None
    self.term_no = None
    self.out_order_id = None
    self.order_id = None
    self.chn_transaction_id = None
    self.ori_order_id = None
    self.trans_time = None
    self.amount = None
    self.fee_type = None
    self.card_type = None
    self.trans_fee = None
    self.finnal_fee = None
    self.sub_openid = None

    if response_dict:
      self.merch_no = response_dict.get('merch_no')
      self.term_no = response_dict.get('term_no')
      self.out_order_id = response_dict.get('out_order_id')
      self.order_id = response_dict.get('order_id')
      self.chn_transaction_id = response_dict.get('chn_transaction_id')
      self.ori_order_id = response_dict.get('ori_order_id')
      self.trans_time = response_dict.get('trans_time')
      self.amount = response_dict.get('amount')
      self.fee_type = response_dict.get('fee_type')
      self.card_type = response_dict.get('card_type')
      self.trans_fee = response_dict.get('trans_fee')
      self.finnal_fee = response_dict.get('finnal_fee')
      self.sub_openid = response_dict.get('sub_openid')


class SettleBillQueryRequest(OrgBaseReq):
  """商户结算账单查询请求"""

  API_URL = "/open/bill/settle-bill/query"

  def __init__(self):
    """初始化商户结算账单查询请求"""
    super().__init__()
    self.merch_no = None
    self.start_busi_date = None
    self.end_busi_date = None
    self.start_settle_date = None
    self.end_settle_date = None
    self.pay_status = None

  def set_merch_no(self, merch_no):
    """
    设置商户号

    Args:
        merch_no: 嘉联分配的商户号

    Returns:
        SettleBillQueryRequest实例
    """
    self.merch_no = merch_no
    return self

  def set_start_busi_date(self, start_busi_date):
    """
    设置开始订单交易日期

    Args:
        start_busi_date: 开始订单交易日期，格式为yyyy-MM-dd

    Returns:
        SettleBillQueryRequest实例
    """
    self.start_busi_date = start_busi_date
    return self

  def set_end_busi_date(self, end_busi_date):
    """
    设置结束订单交易日期

    Args:
        end_busi_date: 结束订单交易日期，格式为yyyy-MM-dd

    Returns:
        SettleBillQueryRequest实例
    """
    self.end_busi_date = end_busi_date
    return self

  def set_start_settle_date(self, start_settle_date):
    """
    设置开始订单结算日期

    Args:
        start_settle_date: 开始订单结算日期，格式为yyyy-MM-dd

    Returns:
        SettleBillQueryRequest实例
    """
    self.start_settle_date = start_settle_date
    return self

  def set_end_settle_date(self, end_settle_date):
    """
    设置结束订单结算日期

    Args:
        end_settle_date: 结束订单结算日期，格式为yyyy-MM-dd

    Returns:
        SettleBillQueryRequest实例
    """
    self.end_settle_date = end_settle_date
    return self

  def set_pay_status(self, pay_status):
    """
    设置付款状态

    Args:
        pay_status: 付款状态，枚举值：0-待付款，1-付款成功，2-付款失败，3-无需付款

    Returns:
        SettleBillQueryRequest实例
    """
    self.pay_status = pay_status
    return self


class SettleBillQueryResponse(BaseResponse):
  """商户结算账单查询响应"""

  def __init__(self, response_dict=None):
    """
    初始化商户结算账单查询响应

    Args:
        response_dict: 响应字典
    """
    super().__init__(response_dict)
    self.err_msg = None
    self.merch_no = None
    self.start_busi_date = None
    self.end_busi_date = None
    self.start_settle_date = None
    self.end_settle_date = None
    self.pay_amt = None
    self.trans_count = None
    self.bill_detail_list = None

    if response_dict:
      self.err_msg = response_dict.get('err_msg')
      self.merch_no = response_dict.get('merch_no')
      self.start_busi_date = response_dict.get('start_busi_date')
      self.end_busi_date = response_dict.get('end_busi_date')
      self.start_settle_date = response_dict.get('start_settle_date')
      self.end_settle_date = response_dict.get('end_settle_date')
      self.pay_amt = response_dict.get('pay_amt')
      self.trans_count = response_dict.get('trans_count')
      self.bill_detail_list = response_dict.get('bill_detail_list')